/*
Copyright (C) 2022-2024 Inspur Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/
package service

import (
	"icep/bean/entity"
	"icep/bean/model"
)

func (is *IcepService) GetUserByUserId(userId string) (*entity.IcepUser, bool) {
	user := new(entity.IcepUser)
	result, err := is.DbEngine.Where("id = ?", userId).Get(user)
	if err != nil {
		log.Errorf("func GetUserByUserId query database error: %s", err)
	}
	return user, result
}

func (is *IcepService) GetIdentityByTenantId(tenantId string) (*model.Identity, bool) {
	identity := new(model.Identity)
	result, err := is.DbEngine.SQL("select tenant_id, ibaas_user_id, league_name, org_name, chain_name, enroll_secret, "+
		"iti.id as identity_id, prv_key, pub_key, cert, status from icep_tenant it left join icep_tenant_identity iti on it.id = iti.tenant_id "+
		"where status = '1' and tenant_id = ?", tenantId).Get(identity)
	if err != nil {
		log.Errorf("func GetIdentityByTenantId query database error: %s", err)
		return nil, false
	}
	return identity, result
}
